package com.dalianpai.gulimall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author WGR
 * @create 2020/7/27 -- 22:55
 */
@Data
@ToString
public class OrderConfirmVo {

    @Setter @Getter
    List<MemberReceiveAddressEntity> address;
    @Setter @Getter
    List<CartItem> items;
    @Setter @Getter
    Integer integration;
    @Setter @Getter
    Map<Long,Boolean> stocks;

    @Setter @Getter
    String orderToken;


    public Integer getCount(){
        Integer i =0;
        if(items !=null){
            for(CartItem item:items){
               i+=item.getCount();
            }
        }
        return i;
    };

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if(items !=null){
            for(CartItem item:items){
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

    public BigDecimal getPayPrice() {
        return getTotal();
    }
}
